from sqlalchemy import Column, Integer, String, DateTime, func, Float
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

# 闪动账号
class FlashXAccount(Base):
    __tablename__ = 'flashx_account'
    id = Column(Integer, primary_key=True, autoincrement=True)
    phone = Column(String(20))
    password = Column(String(20))
    member_name = Column(String(50))
    access_token = Column(String(255))
    is_admin = Column(Integer)
    last_update = Column(DateTime)
    last_use = Column(DateTime)

class NickNames(Base):
    __tablename__ = 'nick_names'
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(30))
    is_used = Column(Integer)

class PhoneNumbers(Base):
    __tablename__ = 'phone_numbers'
    id = Column(Integer, primary_key=True, autoincrement=True)
    phone = Column(String(30))
    is_used = Column(Integer)
    is_valid = Column(Integer)

class TempActivity(Base):
    __tablename__ = 'temp_activity'
    id = Column(Integer, primary_key=True)
    club_id = Column(Integer)
    member_count = Column(Integer)
    title = Column(String(50))
    city = Column(String(50))
    region = Column(String(50))
    place_name = Column(String(50))
    latitude = Column(Float)
    longitude = Column(Float)
    address = Column(String(255))
    start_hour = Column(String(10))
    end_hour = Column(String(10))
    last_create_date = Column(DateTime)
    price = Column(Integer)

# 闪动用户评论
class UserComments(Base):
    __tablename__ = 'user_comments'
    id = Column(Integer, primary_key=True, autoincrement=True)
    comment_id = Column(Integer)
    content = Column(String(255))
    image_url = Column(String(255))
    is_used = Column(Integer)

class AllClub(Base):
    __tablename__ = 'all_club'
    id = Column(Integer, primary_key=True, autoincrement=True)
    club_id = Column(Integer)

class ClubMember(Base):
    __tablename__ = 'club_member'
    id = Column(Integer, primary_key=True, autoincrement=True)
    club_id = Column(Integer)
    sex = Column(Integer)
    member_id = Column(Integer)
    user_id = Column(Integer)
    level = Column(Integer)
    phone = Column(String(50))
    member_name = Column(String(50))
    member_avatar = Column(String(255))


class ClubHistory(Base):
    __tablename__ = 'club_history'
    id = Column(Integer, primary_key=True, autoincrement=True)
    club_id = Column(Integer)
    member_count = Column(Integer)
    female_count = Column(Integer)
    male_count = Column(Integer)
    update_date = Column(String(20))


class MemberExt(Base):
    __tablename__ = 'member_ext'
    member_id = Column(Integer, primary_key=True)
    member_name = Column(String(50))
    avatar = Column(String(255))
    points = Column(Integer)
    locked_points = Column(Integer)
    act_times = Column(Integer)
    openid = Column(String(100))
    game_times = Column(Integer)
    update_time = Column(DateTime)


class PointHistory(Base):
    __tablename__ = 'points_history'
    id = Column(Integer, primary_key=True, autoincrement=True)
    club_id = Column(Integer)
    member_id = Column(Integer)
    member_name = Column(String(30))
    points = Column(Integer)
    reason = Column(String(50))
    banker = Column(String(20))
    remark = Column(String(255))
    operator = Column(String(20))
    join_date = Column(String(20))
    target_id = Column(Integer)
    create_time = Column(DateTime)


class Activity(Base):
    __tablename__ = 'activity'
    id = Column(Integer, primary_key=True, autoincrement=True)
    act_id = Column(Integer)
    club_id = Column(Integer)
    act_type = Column(Integer)
    act_name = Column(String(100))
    act_date = Column(String(10))
    start_time = Column(Integer)
    end_time = Column(Integer)
    apply_count = Column(Integer)
    new_member_count = Column(Integer)
    male_count = Column(Integer)
    female_count = Column(Integer)
    place_id = Column(Integer)
    place_name = Column(String(100))
    give_out_points = Column(Integer)


class MemberCheckIn(Base):
    __tablename__ = 'member_check_in'
    id = Column(Integer, primary_key=True, autoincrement=True)
    club_id = Column(Integer)
    member_id = Column(Integer)
    check_in_date = Column(String(10))
    create_time = Column(DateTime)


class PointStore(Base):
    __tablename__ = 'point_market'
    id = Column(Integer, primary_key=True, autoincrement=True)
    club_id = Column(Integer)
    title = Column(String(100))
    description = Column(String(255))
    price = Column(Integer)
    goods_image = Column(String(255))
    remain_count = Column(Integer)


class ExchangeOrder(Base):
    __tablename__ = 'exchange_order'
    id = Column(Integer, primary_key=True, autoincrement=True)
    goods_id = Column(Integer)
    goods_count = Column(Integer)
    single_price = Column(Integer)
    total_price = Column(Integer)
    member_id = Column(Integer)
    club_id = Column(Integer)
    create_time = Column(DateTime)
    # -1 取消兑换 0 待确认 1 已确认，待领取 2 驳回请求
    order_status = Column(Integer)
    reason = Column(String(50))
    audit_time = Column(DateTime)
    audit_by = Column(String(20))

class TotalActivity(Base):
    __tablename__ = 'total_activity'
    id = Column(Integer, primary_key=True, autoincrement=True)
    activity_id = Column(Integer)
    club_id = Column(Integer)
    address = Column(String(80))
    activity_date = Column(String(10))
    activity_time = Column(String(30))
    activity_title = Column(String(50))

################################################ 20251122比赛数据 ####################################################
# class Players(Base):
#     __tablename__ = 'game_player'
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     team_code = Column(String(10))
#     team_leader = Column(String(30))
#     man_double_1 = Column(String(50))
#     man_double_2 = Column(String(50))
#     mix_double_1 = Column(String(50))
#     mix_double_2 = Column(String(50))
#     woman_double = Column(String(50))

class GameScore(Base):
    __tablename__ = 'game_score'
    id = Column(Integer, primary_key=True, autoincrement=True)
    ground_no = Column(Integer)
    game_order = Column(Integer)
    team1 = Column(String(10))
    team2 = Column(String(10))
    players1 = Column(String(50))
    players2 = Column(String(50))
    start_time = Column(String(20))
    end_time = Column(String(20))
    score1 = Column(Integer)
    score2 = Column(Integer)
    record_time = Column(DateTime)

class PreFinalScore(Base):
    __tablename__ = 'pre_final_score'
    id = Column(Integer, primary_key=True, autoincrement=True)
    team1 = Column(String(10))
    team2 = Column(String(10))
    score1 = Column(Integer)
    score2 = Column(Integer)
    game_type = Column(String(10))

class FinalScore(Base):
    __tablename__ = 'final_score'
    id = Column(Integer, primary_key=True, autoincrement=True)
    team1 = Column(String(10))
    team2 = Column(String(10))
    score1 = Column(Integer)
    score2 = Column(Integer)
    game_type = Column(String(10))

# class TeamScore(Base):
#     __tablename__ = 'team_score'
#     team_code = Column(String(10))

################################################ 头条统计相关表 ####################################################
class TopActivity(Base):
    __tablename__ = 'top_activity'
    id = Column(Integer, primary_key=True, autoincrement=True)
    activity_id = Column(Integer)
    club_id = Column(Integer)
    club_name = Column(String(50))
    club_level = Column(Integer)
    address = Column(String(80))
    activity_date = Column(String(10))
    activity_time = Column(String(30))
    activity_title = Column(String(50))
    activity_type = Column(Integer)
    activity_avatar = Column(String(255))
    apply_count_start = Column(Integer)
    apply_count_end = Column(Integer)
    new_member_count_start = Column(Integer)
    new_member_count_end = Column(Integer)
    male_count_start = Column(Integer)
    male_count_end = Column(Integer)
    female_count_start = Column(Integer)
    female_count_end = Column(Integer)
    need_count = Column(Integer)
    is_free_play = Column(Integer)
    free_play_count = Column(Integer)
    level_lower = Column(Float)
    level_upper = Column(Float)
    level_average = Column(Float)
    region = Column(String(20))
    start_time = Column(String(30))
    end_time = Column(String(30))
    show_cost = Column(String(20))
    # view_count_start = Column(Integer)
    view_count = Column(Integer)
    display_position = Column(Integer)
    collect_date = Column(String(10))
    collect_hour = Column(Integer)
    collect_weekday = Column(Integer)
    create_time = Column(DateTime, server_default=func.now())
    update_time = Column(DateTime, server_onupdate=func.now())


def to_dict(self):
    return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}


Base.to_dict = to_dict
